package 数据结构和算法.算法.查找算法.插值查找;

public class FindByInterpolation {
    public static void main(String[] args) {
        int[] array = {1, 2, 3, 4, 5, 6, 7, 8};
        System.out.printf(String.valueOf(search(array, 0, array.length - 1, 10)));
    }

    public static boolean search(int[] array, int L, int R, int key) {
        int low = L;
        int hight = R;
        while (low <= hight) {
            int middle = low + (key - array[low]) / (array[hight] - array[low]) * (hight - low);//只换了这句话
            if (key < array[middle]) {
                hight = middle - 1;
            } else if (key > array[middle]) {
                low = middle + 1;
            } else {
                return true;
            }
        }

        return false;
    }
}
